<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    var appealSum = function (s) {
      let ret = 0;
      let last = 0;
      let map = {};
      for (let i = 0; i < s.length; i++) {
        if (map[s[i]] == void 0) {
          last += i + 1;
        } else {
          last += i - map[s[i]] - 1 + 1;
        }

        ret += last;
        map[s[i]] = i;
      }
      return ret;
    };
    console.log(appealSum("abbca"));
  </script>

</body>

</html>